package main

import (
	_ "beegoProject11/models/auth"
	_ "beegoProject11/routers"
	"beegoProject11/utils"
	"fmt"
	"github.com/astaxie/beego"
	"github.com/astaxie/beego/logs"
	"github.com/astaxie/beego/orm"
	_ "github.com/go-sql-driver/mysql"
	"log"
)

/*
9.60【权限管理模块】角色上配置用户三
	1. ToRoleUser 增加绑定与未绑定关系 144H,150-155H
	2. role-user-add.html 55-58H
	3. DoRoleUser 176H

9.61【权限管理模块】角色上配置权限一
	1. role_controller.go ToRoleAuth 定义
	2. 路由
	3. role_list.html 89H

9.62【权限管理模块】角色上配置权限二
	1. GetAuthJson 逻辑
	2. role-auth-add.html 58-59H和113H对比输出效果，


9.63【权限管理模块】角色上配置权限三
	1. 后端添加json GetAuthJson
	2. 路由
	3. role-auth-add.html, 前端编写ajax 61H整体修改

9.64【权限管理模块】角色上配置权限四
	1. 打开页面显示已配置信息 ToRoleAuth
	2. role-auth-add.html 24H,31H,41H,
	3. GetAuthJson 218H，225H，273H
	4. role-auth-add.html 73H,133H,
	5. sys_role_sys_auth数据库增加两条数据

9.65【权限管理模块】角色上配置权限五
	1. role-auth-add.html
	2.
	3.
	4.
	5.
	6.


*/

func init() {
	user := beego.AppConfig.DefaultString("mysql::Username", "root")
	pwd := beego.AppConfig.DefaultString("mysql::Password", "Ideal123")
	host := beego.AppConfig.DefaultString("mysql::Host", "127.0.0.1")
	port := beego.AppConfig.DefaultInt("mysql::Port", 3306)
	dbName := beego.AppConfig.DefaultString("mysql::DbName", "beegoProject")

	dsn := fmt.Sprintf("%s:%s@tcp(%s:%d)/%s?charset=utf8mb4&parseTime=true&loc=PRC",
		user, pwd, host, port, dbName)

	orm.RegisterDriver("mysql", orm.DRMySQL)
	orm.RegisterDataBase("default", "mysql", dsn)

	db, err := orm.GetDB("default")
	if err != nil {
		log.Fatal(err)
	} else if err := db.Ping(); err != nil {
		log.Fatal(err)
	}
}

func main() {
	orm.RunCommand()
	/*	orm.Debug = true*/
	beego.BConfig.WebConfig.Session.SessionOn = true

	// 未登录请求拦截
	beego.InsertFilter("/main/*", beego.BeforeRouter, utils.LoginFilter)

	// 日志
	logs.SetLogger(logs.AdapterMultiFile, `{"filename":"logs/beego.log","separate":["error","info","debug"]}`)

	beego.Run()
}
